// 代码块 importM
import 'package:flutter/material.dart';

import './myFont.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Flutter app"),
        ),
        body: const MyHomePage(),
      ),
    );
  }
}

List listData = [
  {
    "title": 'Candy Shop',
    "author": 'Mohamed Chahin',
    "imageUrl":
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.FYx55PIoNajL-lEV5UhFlAHaNK?rs=1&pid=ImgDetMain",
  },
  {
    "title": 'Candy Shop2',
    "author": 'Mohamed Chahin',
    "imageUrl":
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.FYx55PIoNajL-lEV5UhFlAHaNK?rs=1&pid=ImgDetMain",
  },
  {
    "title": 'Candy Shop3',
    "author": 'Mohamed Chahin',
    "imageUrl":
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.FYx55PIoNajL-lEV5UhFlAHaNK?rs=1&pid=ImgDetMain",
  },
  {
    "title": 'Candy Shop4',
    "author": 'Mohamed Chahin',
    "imageUrl":
        "https://tse3-mm.cn.bing.net/th/id/OIP-C.FYx55PIoNajL-lEV5UhFlAHaNK?rs=1&pid=ImgDetMain",
  },
];

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  List<Widget> _initListData() {
    List<Widget> tempList = [];
    for (var i = 0; i < listData.length; i++) {
      tempList.add(ListTile(
          leading: Image.network("${listData[i]["imageUrl"]}"),
          title: Text("${listData[i]["title"]}"),
          subtitle: Text("${listData[i]["author"]}")));
    }
    return tempList;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: _initListData(),
    );
  }
}
